package es.ats.codington.web.servlets;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import es.ats.codington.festival.domain.Place;
import es.ats.codington.festival.services.PlaceService;

/**
 * Servlet implementation class EventByPlaceServletMarket
 */
@WebServlet("/EventByPlaceServletMarket")
public class EventByPlaceServletMarket extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public EventByPlaceServletMarket() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		PlaceService ps = new PlaceService();
		ArrayList<Integer> idsplace = new ArrayList<Integer>();
		ArrayList<Place> allplaces = new ArrayList<Place>();
		int iter;
		int size;
		
		try{
			String type = (String) request.getParameter("type");
			
			idsplace= ps.getIdsPlace(type);
			size= idsplace.size();
			
			for (iter=0; iter<size; iter++){
				int id= idsplace.get(iter);
				Place place = ps.viewPlace(id);
				allplaces.add(place);
			}
					
			int siz= allplaces.size();
			request.setAttribute("size", siz);
			request.setAttribute("places", allplaces);
			RequestDispatcher dispatcher = request.getRequestDispatcher("/EventsByPlaceSouth.jsp"); 
			dispatcher.forward(request, response);  
		
		}catch(Exception ex){
			ex.getMessage();
			
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
